﻿function ClientAddProfile() {
    Url = Portal.OfficeMan.Profile.GetAddUrl().value;
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
    ClientReading();
}

function ClientSaveAddProfile() {
    ProfileCode = document.getElementById("txtProfileCode").value;
    ProfileName = document.getElementById("txtProfileName").value;
    Description = document.getElementById("txtDescription").value;
    OpenDate = document.getElementById("txtOpenDate").value;
    ExpireDate = document.getElementById("txtExpireDate").value;

    RetValue = Portal.OfficeMan.AddProfile.ServerSideAddProfile(ProfileCode, ProfileName, Description, OpenDate, ExpireDate).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    document.getElementById("txtProfileCode").value = "";
    document.getElementById("txtProfileName").value = "";
    document.getElementById("txtDescription").value = "";
    document.getElementById("txtOpenDate").value = "";
    document.getElementById("txtExpireDate").value = "";
    document.getElementById("txtProfileCode").focus();
    //window.close();
}

function ClientUpdateProfile(ProfileId) {
    Url = Portal.OfficeMan.Profile.GetUpdateUrl(ProfileId).value;
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    ClientReading();
}

function ClientDeleteProfile(ProfileId)
{
    Msg=Portal.OfficeMan.Profile.GetConfirmDeleteMsg().value;
    if(confirm(Msg)==false)return;
    RetValue = Portal.OfficeMan.Profile.ServerSideDeleteProfile(ProfileId).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
}



function ShowClientUpdateUrlForm(ProfileId)
{
    Url = Portal.OfficeMan.Profile.GetUpdateUrl(ProfileId).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;'); 
}


function ClientSaveUpdateProfile(ProfileId)
{
    ProfileCode = document.getElementById("txtProfileCode").value;
    ProfileName = document.getElementById("txtProfileName").value;
    Description = document.getElementById("txtDescription").value;
    OpenDate = document.getElementById("txtOpenDate").value;
    ExpireDate = document.getElementById("txtExpireDate").value;

    ProfileName = document.getElementById("txtProfileName").value;

    RetValue = Portal.OfficeMan.UpdateProfile.ServerSideUpdateProfile(ProfileId, ProfileCode, ProfileName, Description,OpenDate,ExpireDate).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    window.close();
}

function ClientReading() {
   document.getElementById("divProcessing").innerHTML = Portal.OfficeMan.Profile.GetProcessingText().value;
   setTimeout("RealClientReading()",10);
}

function RealClientReading() {
    Keyword = document.getElementById("txtKeyword").value;
    
    OpenFromDate = document.getElementById("txtOpenFromDate").value;
    OpenToDate = document.getElementById("txtOpenToDate").value;

    CloseFromDate = document.getElementById("txtCloseFromDate").value;
    CloseToDate = document.getElementById("txtCloseToDate").value;

    rValue = Portal.OfficeMan.Profile.GetProfile(Keyword, OpenFromDate, OpenToDate, CloseFromDate, CloseToDate).value;
    document.getElementById("divProfileContent").innerHTML = rValue;
    document.getElementById("divProcessing").innerHTML = "";
}


function ClientViewDetailProfile(ProfileId)
{
    Url = Portal.OfficeMan.Profile.GetViewDetailUrl(ProfileId).value;
    window.open(Url,'_blank');
}